/*
 * Copyright 2010 Mttang.com All right reserved. This software is the confidential and proprietary information of
 * Mttang.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Mttang.com.
 */
package com.mttang.sys.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.mttang.framework.core.pojos.ServiceRequest;
import com.mttang.framework.core.pojos.ServiceResponse;
import com.mttang.framework.core.web.controller.BaseDispatcherMultiActionController;
import com.mttang.sys.biz.action.MenuAction;
import com.mttang.util.InfoAppKeyConstant;
import com.mttang.util.SysBeanConstant;

/**
 * 类IndexJspController.java的实现描述：登入首页的操作TODO 类实现描述
 * 
 * @author 
 */
public class IndexJspController extends BaseDispatcherMultiActionController {

	private MenuAction menuAction;
	
    public void setMenuAction(MenuAction menuAction) {
		this.menuAction = menuAction;
	}
	
    /**
     * 首页TOP
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView topFrame(HttpServletRequest request, HttpServletResponse response) throws Exception {

        return new ModelAndView("top", "success_view", null);
    }

    /**
     * 首页左边菜单区域
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView leftFrame(HttpServletRequest request, HttpServletResponse response) throws Exception {

        try {
            if (logger.isInfoEnabled()) {
                logger.info("调用远程接口: menuAction");
            }
            String roleId=String.valueOf(((Map)request.getSession().getAttribute("user")).get("roleId"));
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("roleId", roleId);
            Map<Object, Object> model = menuAction.left(map);
            return new ModelAndView("left", "str", model.get("str"));
        } catch (Exception e) {
        	logger.error(e.getStackTrace(),e);
            return new ModelAndView("erroe", "error_view", "Oops, error occur...");
        }
    
    }

    /**
     * 首页的框架的一部分
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView lineFrame(HttpServletRequest request, HttpServletResponse response) throws Exception {

        return new ModelAndView("line", "success_view", null);
    }

    /**
     * 一级菜单
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView tagFrame(HttpServletRequest request, HttpServletResponse response) throws Exception {



        try {
            if (logger.isInfoEnabled()) {
                logger.info("调用远程接口: menuAction");
            }
            String roleId=String.valueOf(((Map)request.getSession().getAttribute("user")).get("roleId"));
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("roleId", roleId);
            Map<Object, Object> model = menuAction.top(map);
            return new ModelAndView("tag", "bean", model);
        } catch (Exception e) {
        	 logger.error(e.getStackTrace(),e);
            return new ModelAndView("error", "error_view", "Oops, error occur...");
        }
    
    }

    /**
     * 首页内容区域
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView mainFrame(HttpServletRequest request, HttpServletResponse response) throws Exception {

        return new ModelAndView("main", "success_view", null);
    }
    
    /**
     * 退出登入
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView loginOut(HttpServletRequest request, HttpServletResponse response) throws Exception {

        request.getSession().removeAttribute("user");
        return new ModelAndView("loginout", "success_view", null);
    }

}
